package org.apm.data.delete;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apm.data.Config;

import java.util.*;

public class DeleteConfig extends Config {

    static final String CLUSTER_NAME;
    static final String CLUSTER_MASTER_IP;
    static final Set<String> DELETE_MULTI_TYPE;
    static final Map<String, Integer> hosts = new HashMap<>();

    private static final Logger LOGGER = LogManager.getLogger(DeleteConfig.class);
    private static final String DELETE_PROPERTIES = "delete.properties";

    static {
        LOGGER.info("Reading configuration:" + DELETE_PROPERTIES);

        Properties props = loadProperties(DELETE_PROPERTIES);

        // es
        CLUSTER_NAME = props.getProperty("es_cluster_name", "Apm");
        String host_str = props.getProperty("es_host_address", "[localhost]");
        CLUSTER_MASTER_IP = props.getProperty("es_cluster_masterIp", "harmonycloud");

        DELETE_MULTI_TYPE = JSON.parseObject(props.getProperty("delete_multi_type", "[]")
                , new TypeReference<Set<String>>(){});

        try {
            getHosts(host_str, hosts);
        } catch (Exception exception) {
            LOGGER.error(exception.getMessage(), exception);
        }

        LOGGER.info("elasticsearch-client: { clusterName: " + CLUSTER_NAME + " ,apmIndex: " + CLUSTER_MASTER_IP
                + " ,host: " + hosts + " ,masterIp: " + CLUSTER_MASTER_IP + " }");
    }

    private DeleteConfig() {}
}
